﻿<controls:ChildWindow xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"  
           xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"  
           x:Class="IndexMarkSilverlightClient.Views.AddAnswerWindow"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:viewmodel="clr-namespace:IndexMarkSilverlightClient.Views" 
           xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
           xmlns:sharedcontrols="clr-namespace:SharedCode.Controls;assembly=SharedCode"    
           xmlns:sharedconverters="clr-namespace:SharedCode.Converters;assembly=SharedCode"
           xmlns:classes="clr-namespace:IndexMarkSilverlightClient.Classes"
           Width="600" Height="500" 
           Title="Добавление показателя">

    <controls:ChildWindow.Resources>
        <viewmodel:AddAnswerViewModel x:Key="AddAnswerViewModel"/>
        <sharedconverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <classes:ContrVisToBoolConverter x:Key="ContrVisToBoolConverter"/>
        <classes:BoolToBrushConverter x:Key="BoolToBrushConverter"/>

        <Style TargetType="controls:TreeViewItem" x:Key="ExpandedStyle">
            <Setter Property="IsExpanded" Value="False" />
        </Style>
    </controls:ChildWindow.Resources>

    <Grid x:Name="LayoutRoot" Margin="2" Style="{StaticResource GridStyle}">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition MaxHeight="370"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Border BorderBrush="Gray" BorderThickness="1" Margin="0, 3, 0, 3" CornerRadius="3">
            <StackPanel Orientation="Horizontal" Grid.Row="0">
                <TextBlock Margin="5, 0, 0, 0" Height="40" Name="textBlock1" TextWrapping="Wrap" FontSize="12" Text="Показатель: " VerticalAlignment="Center" FontWeight="Bold"/>
                <TextBlock Height="40" Name="textBlock2" Width="420" TextWrapping="Wrap" FontSize="12" Text="{Binding CurrentChar.Name, Source={StaticResource AddAnswerViewModel}}" VerticalAlignment="Center" ToolTipService.ToolTip="{Binding CurrentChar.Name}"/>
            </StackPanel>
        </Border>

        <Border BorderBrush="Gray" BorderThickness="1" Margin="0, 3, 0, 3" Grid.Row="1" CornerRadius="3">
            <StackPanel Orientation="Vertical" >

                <TextBlock Text="Градации:" FontSize="12" Margin="5" FontWeight="Bold" Foreground="#FF285A5A" Visibility="{Binding IsGraduated, Source={StaticResource AddAnswerViewModel}, Converter={StaticResource BoolToVisibilityConverter}}"/>

                <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="300" MaxHeight="300" Visibility="{Binding IsGraduated, Source={StaticResource AddAnswerViewModel}, Converter={StaticResource BoolToVisibilityConverter}}">

                    <ListBox x:Name="GradationsListBox" ItemsSource="{Binding Gradations, Source={StaticResource AddAnswerViewModel}}" 
                     Background="Transparent" BorderBrush="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource NotSelectedListBoxItemStyle}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="*" Margin="2, 0, 2, 0" Foreground="Red" ToolTipService.ToolTip="Обязательна для заполнения"
                                                   Visibility="{Binding IsNecessary, Converter={StaticResource BoolToVisibilityConverter}}"/>
                                        <TextBlock Text="{Binding Name}" Width="440" TextWrapping="Wrap" FontWeight="Bold" Margin="5, 0, 0, 0"/>
                                    </StackPanel>

                                    <Border CornerRadius="2" BorderThickness="1" BorderBrush="{Binding IsCorrect, Converter={StaticResource BoolToBrushConverter}}"
                                            Visibility="{Binding NotHasChilds, Converter={StaticResource BoolToVisibilityConverter}}">
                                        <StackPanel Orientation="Horizontal" Margin="2">
                                            <my:NumericUpDown DecimalPlaces="2" Width="450" Margin="5, 0, 0, 0" Maximum="99999999" Minimum="0" Increment="1" Value="{Binding Volume, Mode=TwoWay}" KeyUp="NumericUpDown_KeyUp" ValueChanged="NumericUpDown_ValueChanged"/>
                                            <TextBlock Text="(" Margin="2, 0, 0, 0"/>
                                            <TextBlock Text="{Binding Unit}"/>
                                            <TextBlock Text=")"/>
                                        </StackPanel>
                                    </Border>

                                    <controls:TreeView ItemsSource="{Binding Childs}"
                                                       Background="Transparent" BorderBrush="{Binding IsCorrect, Converter={StaticResource BoolToBrushConverter}}"
                                                       Margin="5, 0, 0, 0" ItemContainerStyle="{StaticResource ExpandedStyle}" 
                                                       Visibility="{Binding NotHasChilds, Converter={StaticResource ContrVisToBoolConverter}}">
                                        <controls:TreeView.ItemTemplate>
                                            <common:HierarchicalDataTemplate ItemsSource="{Binding Childs}">
                                                <StackPanel Orientation="Horizontal">
                                                    <RadioButton GroupName="{Binding Group}" IsChecked="{Binding IsSelected}" Content="{Binding FullName}" Checked="RadioButton_Checked" ToolTipService.ToolTip="{Binding FullName}" Visibility="{Binding NotHasChilds, Converter={StaticResource BoolToVisibilityConverter}}"/>
                                                    <TextBlock Text="{Binding FullName}" Visibility="{Binding NotHasChilds, Converter={StaticResource ContrVisToBoolConverter}}" ToolTipService.ToolTip="{Binding FullName}"/>
                                                </StackPanel>
                                            </common:HierarchicalDataTemplate>
                                        </controls:TreeView.ItemTemplate>
                                    </controls:TreeView>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                </ScrollViewer>

                <StackPanel Orientation="Horizontal" Margin="5">
                    <TextBlock Text="Объем показателя:" FontWeight="Bold"/>

                    <my:NumericUpDown DecimalPlaces="2" Width="360" Margin="5, 0, 0, 0" Increment="1" Minimum="0" Maximum="99999999" 
                                      Value="{Binding Answer.Volume, UpdateSourceTrigger=Explicit, Source={StaticResource AddAnswerViewModel}}" 
                                      ValueChanging="NumericUpDown_ValueChanging" KeyUp="NumericUpDown_KeyUp_1" FontWeight="Bold"
                                      Visibility="{Binding IsYesNoUnit, Source={StaticResource AddAnswerViewModel}, Converter={StaticResource ContrVisToBoolConverter}}"/>

                    <StackPanel Orientation="Horizontal" Margin="2" Width="60" Visibility="{Binding IsYesNoUnit, Source={StaticResource AddAnswerViewModel}, Converter={StaticResource ContrVisToBoolConverter}}">
                        <TextBlock Text="(" Margin="2, 0, 0, 0"/>
                        <TextBlock Text="{Binding Path=CurrentChar.Unit, Source={StaticResource AddAnswerViewModel}}"/>
                        <TextBlock Text=")"/>
                    </StackPanel>

                    <Border BorderThickness="1" Visibility="{Binding IsYesNoUnit, Source={StaticResource AddAnswerViewModel}, Converter={StaticResource BoolToVisibilityConverter}}" BorderBrush="Gray">
                        <TextBlock Text="Да" Margin="5, 2, 0, 0" Width="420"/>
                    </Border>
                </StackPanel>

            </StackPanel>
        </Border>

        <Button x:Name="CancelButton" Content="Отмена" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="2" ToolTipService.ToolTip="Отменить изменения"/>
        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="2" ToolTipService.ToolTip="Сохранить изменения" IsEnabled="{Binding IsCorrect, Source={StaticResource AddAnswerViewModel}}"/>

        <sharedcontrols:LoadingBar x:Name="loadingBar" VerticalAlignment="Center" Action="загрузка" HorizontalAlignment="Center" Grid.RowSpan="3"/>

    </Grid>

</controls:ChildWindow>